﻿using System.Collections;
using Assets.AnimationPlayer.Scripts.Prefabs;
using Assets.AnimationPlayer.Scripts.UI.controls;
using Assets.AnimationPlayer.Scripts.Util;
using UnityEngine;

namespace Assets.AnimationPlayer.Scripts.UI
{
    public class AnimationSubPage: MonoBehaviour
    {
        public GameObject GameUiMain;
        public TopBarControl TopBarControl;
        public GameObject LoadingView;

        public void BindClickEvents(YioksCallBack.CallBackFun backCallBack)
        {
            TopBarControl.BindEvents(backCallBack);
        }


        public IEnumerator StartLoading(YioksCallBack.CallBackFun callback)
        {
            if (LoadingView != null)
            {
                LoadingView.SetActive(true);
                LoadingView.transform.Find("RoateImage").GetComponent<RoateImage>().BeginLoading();
            }
            yield return new WaitForEndOfFrame();
            if (AnimationVar.AnimationPlayCfg.SelectAnimationObj != null && callback != null)
                callback.Invoke();
        }

        public IEnumerator StopLoading(YioksCallBack.CallBackFun callback)
        {
            if (LoadingView != null)
            {
                LoadingView.transform.Find("RoateImage").GetComponent<RoateImage>().StopLoading();
                LoadingView.SetActive(false);
            }
            yield return new WaitForEndOfFrame();
            if(callback != null)
                callback.Invoke();
        }

    }
}
